Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RPC endpoints to support Trustwallet staking #1475

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

atchapcyp
Copy link
Contributor

@atchapcyp atchapcyp commented Sep 9, 2019

In order to support staking with trustwallet, We need to provide RPC endpoints to fetch the following data:

  • Validators list
  • ListDelegations
  • Current annual APR (calculate by validator fee)
  • GetAccountInfo
  • BroadcastTransaction

ref : https://developer.trustwallet.com/staking#step-3-define-rpc-endpoints-for-blockatlas
Issue ref : #1461

  • I added unit tests for any code that added
  • I updated the CHANGELOG.md
  • All IP is original and not copied from another source
  • I assign all copyright to Loom Network for the code in the pull request

getValidatorResponse := make([]blockatlas.Validator, 0)
chainID := ctx.Block().ChainID

for _, validator := range validators {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loop has time complexity equal to n^2. We can do it better by using hash map.

First we loop to save validator address in hash map like

validatorList := map[string]loom.Address
for _, validator := range validators {
  validatorList[string(validator.Pubkey)] = loom.Address{ChainID: chainID, Local: loom.LocalAddressFromPublicKey(validator.PubKey)}
}

and then we can just iterate candidates that are in the validators list

@atchapcyp atchapcyp changed the title Add GetValidator method for RPC endpoint Add RPC endpoints to support Trustwallet staking Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants